import Axios from '../plugins/axios'
import { HTTPTypes } from './type'
import { baseURL } from './config'

const ucApi = `${baseURL}/uc/api`

export class LoginRequest {
  /**
   * 登录
   * @param params
   * @returns
   * code/getsms -> login -> accessToken -> isAvailable -> getResourceTree获取权限树
   */
  static async getAuthCode(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/code/getsms`, { ...params }) // 如果后续有修改参数的需求，可以使用浅拷贝添加其他参数，不会影响 params
  }

  /**
   * 登录滑块之后，需要走这个接口拿到captchaVerification来获取接口
   * @param params
   * @returns
   */
  static async getSmsCertificate(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/code/getSmsCertificateNew`, params)
  }

  static async getUserCode(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/loginNew`, params)
  }

  static async getToken(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/accessTokenNew`, params)
  }

  static async getAvailable(): Promise<HTTPTypes['res']> {
    return Axios.get(`${ucApi}/account/isAvailable`)
  }

  static async getResourceTree(params?: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/account/resource/getResourceTree2`, params)
  }

  // 获取图形验证码
  static async getLoginCode(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/code/getsmsNew`, params)
  }

  // 重置密码
  static async resetPassword(params: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/resetPassword`, params)
  }

  // 验证手机验证码[忘记密码]
  static async checkPhoneSmsCode(params?: HTTPTypes['req']): Promise<HTTPTypes['res']> {
    return Axios.post(`${ucApi}/code/verificationCode`, params)
  }
}
